﻿using BLL;
using MODEL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Loginter.承运单管理
{
    public partial class UpdateCarries : System.Web.UI.Page
    {
        CarrierBLL carr = new CarrierBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int id = Convert.ToInt32(Request.QueryString["id"]);
                if (id == 0)
                {
                    Server.Transfer("CarriersGuanli.aspx");
                }
                GetUpdate();
            }
        }

        private void GetUpdate()
        {
            //接收传递过来的id
            int id = Convert.ToInt32(Request.QueryString["id"]);
            //通过id从model里获取数据并赋值
            CarrierMODEL cm = carr.GetCarriersID(id);
            txt_SendCompany.Text = cm.SendCompany;
            txt_SendCompanyAddress.Text = cm.SendAddress;
            txt_SendPhone.Text = cm.SendPhone;
            txt_SendLinkMan.Text = cm.SendLinkman;
            txt_ReceiveCompany.Text = cm.ReceiveCompany;
            txt_ReceiveCompanyAddress.Text = cm.FK_ReceiveAddress;
            txt_ReceivePhone.Text = cm.ReceviePhone;
            txt_ReceiveLinkMan.Text = cm.ReceiveLinkman;
            txt_InsuranceCost.Text = Convert.ToString(cm.InsuranceCosst);
            txt_TransportCost.Text = Convert.ToString(cm.TransportCost);
            txt_OtherCost.Text = Convert.ToString(cm.OtherCost);
        }

        protected void btn_update_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(Request.QueryString["id"]);
            //获取数据并赋值
            CarrierinfoMODEL car = new CarrierinfoMODEL()
            {
                SendCompany = txt_SendCompany.Text.Trim(),
                SendAddress = txt_SendCompanyAddress.Text.Trim(),
                SendPhone = txt_SendPhone.Text.Trim(),
                SendLinkman = txt_SendLinkMan.Text.Trim(),
                ReceiveCompany = txt_ReceiveCompany.Text.Trim(),
                FK_ReceiveAddress = txt_ReceiveCompanyAddress.Text.Trim(),
                ReceviePhone = txt_ReceivePhone.Text.Trim(),
                ReceiveLinkman = txt_ReceiveLinkMan.Text.Trim(),
                InsuranceCosst = float.Parse(txt_InsuranceCost.Text.Trim()),
                TransportCost = float.Parse(txt_TransportCost.Text.Trim()),
                OtherCost = float.Parse(txt_OtherCost.Text.Trim()),
                CarriersID = id
            };
            //调用更新方法
            int upda = carr.UpCarriage(car);
            if (upda > 0)
            {
                Response.Write("<script>alert('更新成功！');location.href='CarriersGuanli.aspx';</script>");
            }
            else
            {
                Response.Write("<script>alert('更新失败！');</script>");
            }
        }
        /// <summary>
        /// 返回列表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_submit_Click1(object sender, EventArgs e)
        {
            Response.Redirect("CarriersGuanli.aspx");
        }
    }
}